﻿using System;
using System.Collections.Generic;
using Types.Enumerations;

namespace Types.CustomTypes
{
    [Serializable()]
    public class ReportHelper
    {
        private string mRaporAdi;
        private string mRaporDosyaAd;
        private EnumReportFormats mRaporFormat = EnumReportFormats.EXCEL;
        private EnumBrowserBehavior mTarayiciDavranisi = EnumBrowserBehavior.Attachment;
        private List<RaporParametre> mParametreList;


        private static Dictionary<int, string> mRaporFormatDictionary;

        // 2009-07-31
        private string mEmailTo;
        private EnumReportDelivery mRaporDelivery;

        static ReportHelper()
        {
            mRaporFormatDictionary = new Dictionary<int, string>();

            foreach (object sKey in Enum.GetValues(typeof(EnumReportFormats)))
                mRaporFormatDictionary.Add(Convert.ToInt32(sKey), Enum.GetName(typeof(EnumReportFormats), sKey));
        }

        public static Dictionary<int, string> RaporFormatDict
        {
            get
            {
                return mRaporFormatDictionary;
            }
        }


        private ReportHelper()
        { }
        public ReportHelper(string pRaporAdi)
        {
            mRaporAdi = pRaporAdi;
            mParametreList = new List<RaporParametre>();
        }

        public string RaporAdi
        {
            get
            {
                return mRaporAdi;
            }
            set
            {
                mRaporAdi = value;
            }
        }

        public string RaporDosyaAd
        {
            get
            {
                return mRaporDosyaAd;
            }
            set
            {
                mRaporDosyaAd = value;
            }
        }

        public EnumReportFormats RaporFormat
        {
            get
            {
                return mRaporFormat;
            }
            set
            {
                mRaporFormat = value;
            }
        }

        public List<RaporParametre> RaporParametreleri
        {
            get
            {
                return mParametreList;
            }
        }

        public EnumBrowserBehavior TarayiciDavranisi
        {
            get
            {
                return mTarayiciDavranisi;
            }
            set
            {
                mTarayiciDavranisi = value;
            }
        }

        // 2009-07-31
        public string SubscriberEMail
        {
            get
            {
                return mEmailTo;
            }
            set
            {
                mEmailTo = value;
            }
        }

        public EnumReportDelivery DeliveryType
        {
            get
            {
                return mRaporDelivery;
            }
            set
            {
                mRaporDelivery = value;
            }
        }

        public string RaporFormatString
        {
            get
            {
                switch (RaporFormat)
                {
                    case EnumReportFormats.EXCEL:
                        return @"EXCEL";
                    case EnumReportFormats.PDF:
                        return @"PDF";
                    case EnumReportFormats.XML:
                        return @"XML";
                    case EnumReportFormats.IMAGE:
                        return @"IMAGE";
                    case EnumReportFormats.MHTML:
                        return @"MHTML";
                }
                return string.Empty;
            }
        }

        public string DeviceInfo
        {

            get
            {
                switch (RaporFormat)
                {
                    case EnumReportFormats.PDF:
                        return null;
                    //                        return @"<DeviceInfo>
                    //                                    <Startpage>0</Startpage>
                    //                                    <PageHeight>11in</PageHeight>
                    //                                    <PageWidth>8.5in</PageWidth>
                    //                                </DeviceInfo>";
                    case EnumReportFormats.EXCEL:
                        return null;
                    case EnumReportFormats.IMAGE:
                        return null;
                    case EnumReportFormats.XML:
                        return null;
                    default:
                        return null;
                }


            }

        }

        public void ParametreEkle(string pParametreAdi, bool pDegeri)
        {
            mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString()));
        }

        public void ParametreEkle(string pParametreAdi, int pDegeri)
        {
            mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString()));
        }

        public void ParametreEkle(string pParametreAdi, int? pDegeri)
        {
            if (pDegeri.HasValue)
                mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString()));
            else
                mParametreList.Add(new RaporParametre(pParametreAdi, null));
        }

        public void ParametreEkle(string pParametreAdi, string pDegeri)
        {
            mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString()));
        }

        public void ParametreEkle(string pParametreAdi, DateTime pDegeri)
        {
            mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString("yyyy-MM-dd HH:mm:ss")));
        }

        public void ParametreEkle(string pParametreAdi, DateTime? pDegeri)
        {
            if (pDegeri.HasValue)
                mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.Value.ToString("yyyy-MM-dd HH:mm:ss")));
            else
                mParametreList.Add(new RaporParametre(pParametreAdi, null));
        }

        public void ParametreEkle(string pParametreAdi, float pDegeri)
        {
            mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.ToString()));
        }

        public void ParametreEkle(string pParametreAdi, decimal? pDegeri)
        {
            if (pDegeri.HasValue)
                mParametreList.Add(new RaporParametre(pParametreAdi, pDegeri.Value.ToString()));
            else
                mParametreList.Add(new RaporParametre(pParametreAdi, null));
        }

        public EnumReportFormats RaporFormatiniAl(string sValue)
        {
            switch (sValue)
            {
                case "0":
                    return EnumReportFormats.PDF;
                case "1":
                    return EnumReportFormats.EXCEL;
                case "2":
                    return EnumReportFormats.IMAGE;
                case "3":
                    return EnumReportFormats.XML;
                default:
                    return EnumReportFormats.PDF;
            }
        }

    }


    [Serializable()]
    public class RaporParametre
    {
        public string mParametreAdi;
        public string mParametreDegeri;

        private RaporParametre()
        { }
        public RaporParametre(string pParamAdi, string pParamValue)
        {
            mParametreAdi = pParamAdi;
            mParametreDegeri = pParamValue;
        }


    }



}
